package com.lf.cloud.grab.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.Controller;
import com.lf.cloud.comm.controller.BaseController;
import com.lf.cloud.comm.modal.dto.ResponeObj;
import com.lf.cloud.grab.business.GrabBusiness;
import com.lf.cloud.grab.task.GrabImgDataTask;
import com.lf.conf.MyConstants;

public class GrabController extends BaseController {

	
	GrabBusiness  grabBusiness = new GrabBusiness();
	
	
	public void grabImgData(){
		
		
		String localPath = "D://Manipula/Manipula/pic/aimeishishang/";
		String uploadType = MyConstants.UPLOADTYPE;
		
		
		String urlStr = "http://www.aimeishishang.com/ArisaraKarbdecho/";
		
		urlStr = "http://www.aimeishishang.com/gaoqingjingxuan/";
		urlStr = "http://www.aimeishishang.com/MunkawChaosGirl/";
		urlStr = "http://www.aimeishishang.com/cherry_quahst/";
		urlStr = "http://www.aimeishishang.com/xingganmeinv/";
		
		urlStr = "http://www.aimeishishang.com/tag-1640.html";
		urlStr = "http://www.aimeishishang.com/tag-thread-1593-1.html";
		String servletPath = getRequest().getServletPath();
		String realPath = getRequest().getServletContext().getRealPath("/");
		System.out.println("*******************OK*****************");
		realPath = realPath.substring(0, realPath.indexOf("CloudFile"))+"upload"+File.separator+"grab";
		System.out.println(realPath);
		
		// tag-1640.html --巨乳美女图片
		
		
		try {
			GrabImgDataTask newtask = new GrabImgDataTask( realPath, urlStr);
			Thread thread = new Thread(newtask);
			thread.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		System.out.println("*******************OK*****************");
		ResponeObj obj = new ResponeObj();
		obj.setCode("200");
		super.success(obj);
	}
	
	
	
	
	public void doMainFunction(){
		String filepath = "D:\\\\workspace\\DevTool\\apache-tomcat-7.0.68\\apache-tomcat-7.0.68\\webapps\\upload\\grab";
		File file = new File(filepath);
		String[] list = file.list();
		Map<String , String> map = new HashMap<String , String>();
		for (String str : list) {
			String string = filepath+File.separator+ str;
			File files = new File(string);
			File[] listFiles = files.listFiles();
			for (File obj : listFiles) {
				System.out.println(obj.getName());
				map.put(string, obj.getName());
			}
		}
		System.out.println(map);
		grabBusiness.insertGrabUploadInfToLocal(map);
		ResponeObj obj = new ResponeObj();
		obj.setCode("200");
		super.success(obj);
	}
	
	
	
	public void geetAimeishishang(){
		
		
		
		String urlStr = "http://www.aimeishishang.com/tag-thread-1593-1.html";
		urlStr = "http://www.aimeishishang.com/daxiongmeinv/";
		String servletPath = getRequest().getServletPath();
		String realPath = getRequest().getServletContext().getRealPath("/");
		System.out.println("*******************OK*****************");
		realPath = realPath.substring(0, realPath.indexOf("CloudFile"))+"upload"+File.separator+"grab"+File.separator+"aimeishishang";
		System.out.println(realPath);
		
		// tag-1640.html --巨乳美女图片
		
		
		try {
			GrabImgDataTask newtask = new GrabImgDataTask( realPath, urlStr);
			Thread thread = new Thread(newtask);
			thread.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		
		
		
		ResponeObj obj = new ResponeObj();
		obj.setCode("200");
		super.success(obj);
	}
	
	
	
	
	public void initTags(){
		
		
		
		
		ResponeObj obj = new ResponeObj();
		obj.setCode("200");
		super.success(obj);
	}
	
}
